
function add(times, pass, description) {
    if (!uid) {
        dialog.message("学员选择不正确")
        return
    }

    var obj = xmlModel.get(testCommitPop.index);


    nav.initializeTask(0, 2, "正在提交测试....")
    nav.openTask("提交测试")

    if (testCommitPop.tid) {
        http.put("/test/record.json", {id: testCommitPop.tid}, {
                      passed: pass ? 1 : -1,
                                     times: times,
                                     description: description
                  }, result)
    }
    else {
        http.post("/test/record.json", {}, {
                      member: {id:uid, display: name},
                      test: {id:  obj.id, display:  obj.content},
                      passed: pass ? 1 : -1,
                                       times: times,
                                     description: description
                  }, result)
    }

}

function result(json) {
    nav.value = nav.maximumValue

    if (json.error){
        dialog.message(json.error.description)
    }
    else {
        dialog.toast("添加成功")
    }
}

function open( index, id) {
    testCommitPop.index = index; testCommitPop.open();

    http.get("/test/record.json?t=s", {uid: nav.uid, id: id}, function (json){
        if (json.error) {
            dialog.toast(json.error.description)
        }
        else {
            testCommitPop.tid = json.id
            testCommitPop.load(json.passed == 1, json.description)
        }
    })
}

